﻿using MediatR;
using S.PurchaseAndSales.Domain.Model;
using S.PurchaseAndSales.Api.Application.Command.SheepSaleCommand;
using S.PurchaseAndSales.Infrastructure.Interface.SalesForm;
using AutoMapper;

namespace S.PurchaseAndSales.Api.Application.CommandHandlers.SheepSaleHandler
{
    public class AddCustomerHandler : IRequestHandler<AddCustomerCommand, bool>
    {

        private readonly ICustomerRepository customer;

        private readonly IMapper mapper;

        public AddCustomerHandler(ICustomerRepository customer, IMapper mapper)
        {
            this.customer = customer;
            this.mapper = mapper;
        }
        /// <summary>
        /// 添加客户
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(AddCustomerCommand request, CancellationToken cancellationToken)
        {
            var list = mapper.Map<CustomerInformationModel>(request);
            return await customer.AddAsync(list);
        }
    }
}
